import { FormProps, FormSchema } from '@/components/Table'
import { BasicColumn } from '@/components/Table/src/types/table'
import { pattern } from '@/utils/validate/index'

// 分享配置列表
export function getShareBasicColumns(): BasicColumn[] {
  return [
    {
      title: '邀请参数',
      width: 150,
      dataIndex: 'code'
    },
    {
      title: '姓名',
      width: 140,
      dataIndex: 'name'
    },
    {
      title: '手机号',
      dataIndex: 'phone'
    },
    {
      title: '创建时间',
      dataIndex: 'createDate'
    },
    {
      title: '新增用户数',
      width: 150,
      dataIndex: 'userCount',
      align: 'right'
    },
    {
      title: '状态',
      dataIndex: 'status'
    },
    {
      title: '备注',
      width: 200,
      dataIndex: 'remark'
    },
    {
      title: '操作',
      width: 160,
      dataIndex: 'operate'
    }
  ]
}

export function getSearchFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 100,
    baseColProps: {
      span: 6,
      md: 10,
      xl: 8,
      xxl: 6
    },
    schemas: [
      {
        field: 'code',
        label: '邀请参数',
        component: 'Input'
      },
      {
        field: 'name',
        label: '姓名',
        component: 'Input'
      },
      {
        field: 'phone',
        label: '手机号',
        component: 'Input'
      },
      {
        field: 'status',
        label: '状态',
        component: 'Select',
        componentProps: {
          options: [
            {
              label: '停用',
              value: 0,
              key: 0
            },
            {
              label: '启用',
              value: 1,
              key: 1
            }
          ]
        }
      }
    ]
  }
}

// 分享信息表单
export function getShareFormConfig(): Partial<FormProps> {
  return {
    layout: 'vertical',
    showActionButtonGroup: false,

    baseColProps: {
      span: 24,
      style: {
        marginBottom: '4px'
      }
    },
    schemas: [
      {
        field: 'name',
        component: 'Input',
        label: '姓名',
        required: true,
        componentProps: {
          maxLength: 10
        }
      },
      {
        field: 'phone',
        component: 'Input',
        label: '手机号',
        rules: [
          {
            required: true,
            message: '请输入手机号'
          },
          {
            pattern: pattern.regexp_cell_phone,
            message: '请输入正确的手机号'
          }
        ]
      },
      {
        field: 'code',
        component: 'Input',
        label: '邀请编码',
        required: true,
        componentProps: {
          maxLength: 40
        }
      },
      {
        field: 'remark',
        component: 'InputTextArea',
        label: '备注',
        componentProps: {
          autoSize: { minRows: 3, maxRows: 3 },
          maxLength: 20,
          placeholder: '请输入该邀请链接备注，20字以内'
        }
      }
    ]
  }
}
